package org.wesc.boot.common.utils;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

/**
 * @author Wesley Cheung
 * @date Created in 20:24 2017/12/21
 */
public class PasswordHelper {

    public static final String DEFAULT_PASSWORD = "123456";

    /**
     * 算法名称：md5, sha-1, sha-224, sha-256, sha-384, sha-512
     */
    private static final String ALGORITHM_NAME = "md5";

    /**
     * 迭代次数
     */
    private static final int HASH_ITERATION = 7;

    /**
     * 密码加密
     */
    public static String encryptPassword(String password) {
        return new SimpleHash(ALGORITHM_NAME, password, ByteSource.Util.bytes(password), HASH_ITERATION).toHex();
    }

    /**
     * 默认密码加密
     */
    public static String encryptDefaultPassword() {
        return new SimpleHash(ALGORITHM_NAME, DEFAULT_PASSWORD, ByteSource.Util.bytes(DEFAULT_PASSWORD), HASH_ITERATION).toHex();
    }

}
